<?php
#############################################################################
#  Module Tag Cloud for Opencart 1.4.x From Team SiamOpencart.com		  													           #
#  เว็บผู้พัฒนา www.siamopencart.com ,www.thaiopencart.com                                                                                 #
#  โดย Somsak2004 วันที่ 25 กุมภาพันธ์ 2553                                                                                                            #
#############################################################################
# โดยการสนับสนุนจาก                                                                                                                                            #
# Unitedsme.com : ผู้ให้บริการเช่าพื้นที่เว็บไซต์ จดโดเมน ระบบ Linux                                                                              #
# Net-LifeStyle.com : ผู้ให้บริการเช่าพื้นที่เว็บไซต์์ จดโดเมน ระบบ Linux																           #
# SiamWebThai.com : SEO ขั้นเทพ โปรโมทเว็บขั้นเซียน ออกแบบ พัฒนาเว็บไซต์ / ตามความต้องการ และถูกใจ Google 		   #
#############################################################################
class ControllerModuleTagCloud extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('module/tagcloud');

		$this->document->title = $this->language->get('heading_title');

		$this->load->model('setting/setting');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
			$this->model_setting_setting->editSetting('tagcloud', $this->request->post);

			$this->session->data['success'] = $this->language->get('text_success');

			$this->redirect((HTTPS_SERVER . 'index.php?route=extension/module&token=' . $this->session->data['token']));
		}

		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_left'] = $this->language->get('text_left');
		$this->data['text_right'] = $this->language->get('text_right');
		$this->data['text_no_products'] = $this->language->get('text_no_products');
		$this->data['text_random'] = $this->language->get('text_random');

		$this->data['entry_limit'] = $this->language->get('entry_limit');
		$this->data['entry_min_font_size'] = $this->language->get('entry_min_font_size');
		$this->data['entry_max_font_size'] = $this->language->get('entry_max_font_size');
		$this->data['entry_position'] = $this->language->get('entry_position');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		$this->data['entry_font_function'] = $this->language->get('entry_font_function');

  		$this->data['entry_credit'] = $this->language->get('entry_credit');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');

		$this->data['tab_general'] = $this->language->get('tab_general');

		if (isset($this->error['warning']))
		{
			$this->data['error_warning'] = $this->error['warning'];
		}
		else
		{
			$this->data['error_warning'] = '';
		}
		if (isset($this->error['error_sort_order']))
		{
			$this->data['error_sort_order'] = $this->error['error_sort_order'];
		}
		else
		{
			$this->data['error_sort_order'] = '';
		}
		if (isset($this->error['error_limit']))
		{
			$this->data['error_limit'] = $this->error['error_limit'];
		}
		else
		{
			$this->data['error_limit'] = '';
		}

  		$this->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => (HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token']),
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => (HTTPS_SERVER . 'index.php?route=extension/module&token=' . $this->session->data['token']),
       		'text'      => $this->language->get('text_module'),
      		'separator' => ' :: '
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => (HTTPS_SERVER . 'index.php?route=module/tagcloud&token=' . $this->session->data['token']),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);

		$this->data['action'] = (HTTPS_SERVER . 'index.php?route=module/tagcloud&token=' . $this->session->data['token']);

		$this->data['cancel'] = (HTTPS_SERVER . 'index.php?route=extension/module&token=' . $this->session->data['token']);

		if (isset($this->request->post['tagcloud_limit'])) {
			$this->data['tagcloud_limit'] = $this->request->post['tagcloud_limit'];
		} else {
			$this->data['tagcloud_limit'] = $this->config->get('tagcloud_limit');
		}

		if (isset($this->request->post['tagcloud_min_font_size'])) {
			$this->data['tagcloud_min_font_size'] = $this->request->post['tagcloud_min_font_size'];
		} else {
			$this->data['tagcloud_min_font_size'] = $this->config->get('tagcloud_min_font_size');
		}

		if (isset($this->request->post['tagcloud_max_font_size'])) {
			$this->data['tagcloud_max_font_size'] = $this->request->post['tagcloud_max_font_size'];
		} else {
			$this->data['tagcloud_max_font_size'] = $this->config->get('tagcloud_max_font_size');
		}

		if (isset($this->request->post['tagcloud_position'])) {
			$this->data['tagcloud_position'] = $this->request->post['tagcloud_position'];
		} else {
			$this->data['tagcloud_position'] = $this->config->get('tagcloud_position');
		}

		if (isset($this->request->post['tagcloud_status'])) {
			$this->data['tagcloud_status'] = $this->request->post['tagcloud_status'];
		} else {
			$this->data['tagcloud_status'] = $this->config->get('tagcloud_status');
		}
		
		if (isset($this->request->post['tagcloud_font_function'])) {
			$this->data['tagcloud_font_function'] = $this->request->post['tagcloud_font_function'];
		} else {
			$this->data['tagcloud_font_function'] = $this->config->get('tagcloud_font_function');
		}

		if (isset($this->request->post['tagcloud_sort_order'])) {
			$this->data['tagcloud_sort_order'] = $this->request->post['tagcloud_sort_order'];
		} else {
			$this->data['tagcloud_sort_order'] = $this->config->get('tagcloud_sort_order');
		}

		$this->id       = 'tagcloud';
		$this->template = 'module/tagcloud.tpl';
		$this->children = array(
			'common/header',	
			'common/footer'	
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));

 		$this->render();
	}

	private function validate() {
		if (!$this->user->hasPermission('modify', 'module/tagcloud')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		if (!$this->request->post['tagcloud_sort_order']) {
			$this->error['sort_order'] = $this->language->get('error_sort_order');
		}
		
		if (!$this->request->post['tagcloud_limit']) {
			$this->error['error_limit'] = $this->language->get('error_limit');
		}
		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
}
?>